<template>
	<view class="content" :class="'theme-'+theme">
	<view class="addTitle">
      <view class="titleDetail">
        <view class="titleLeft" > 
			<image src="../../static/newh5/fanhui.png" 
			class="yticon" 
			style="width: 13px;height: 20px;color:black" 
			@click="returnIndex()"
			></image>
        </view>
        <view class="titleCenter" >
          <b class="titleText">消息</b>
        </view>
        <view class="titleRight"  style="color: #269cd3;flex:1" > </view>
      </view>
    </view>
		<view class="menuContent" v-for="(item,index) in menuMessage" :key='index'>
			<list-cell :icon="item.icon" iconSize="36" border='' style="padding-top: 20rpx;"  
			:title="item.menuName" 
			:numberTips='item.messageNumber' 
			@eventClick="navTo(item.url,index)" ></list-cell>
		</view>
	</view>
</template>

<script>
	import {  goback } from "@/common/utils/navigateBack.js";
	import listCell from '@/components/mix-list-cell';
	import {
		mapState
	} from 'vuex';
	import {
		countNoticeNum,
		UndoWorkNum,
		orderNum,
		getMessageNotice,
		isReadOrderOrSys
	} from '../../api/message/message.js'
	export default {
		components: {
			listCell
		},
		data() {
			return {
				menuMessage:[
					{
						menuName:'系统信息',
						icon:'../../static/messageIcon/系统消息icon.png',
						messageNumber:0,
						url:'/pages/message/systeMessage'
					},
					{
						menuName:'订单信息',
						icon:'../../static/messageIcon/订单消息icon.png',
						messageNumber:0,
						url:'/pages/message/orderMessage'
					},
					{
						menuName:'待办事项',
						icon:'../../static/messageIcon/待办事项icon.png',
						messageNumber:0,
						url:'/pages/backlog/backlog'
					},
					{
						menuName:'通知公告',
						icon:'../../static/messageIcon/通知公告icon.png',
						messageNumber:0,
						url:'/pages/message/inform'
					}
				],
				NoticeNum:''
			}
		},
		onShow(){
			if(this.hasLogin){
				this.countNoticeNum()
				this.countSystemNum(76)
				this.countOrderNum(52)
				this.undoNum()
			}
		},
		onLoad(){
			if(this.hasLogin){
				this.countNoticeNum()
				this.countSystemNum(76)
				this.countOrderNum(52)
				this.undoNum()
			}
			
			// this.getMessageNotice()
		},
		computed: {
			...mapState(['hasLogin'])
			// ...mapState(['hasLogin', 'userInfo'])
		},
		mounted(){

		},
		methods: {
			returnIndex() {
				goback()
			},
			//通知公告数量记录
			countNoticeNum(){
				countNoticeNum().then(res=>{
					if(res.code == 0 ){
						// this.NoticeNum = res.data
						this.menuMessage.forEach(item=>{
							if(item.menuName == '通知公告')item.messageNumber =Number( res.data);
						})
					}
				})
			},
			//获取系统信息
			countSystemNum(type){
				const params = {
					bizParentType:76
				}
				orderNum(params).then(res=>{
					if(res.code == 0 ){
						// this.NoticeNum = res.data
						this.menuMessage.forEach(item=>{
							if(item.menuName === '系统信息')item.messageNumber = Number( res.data);
						})
					}
				})
			},
			//订单信息数量条数更新
			countOrderNum(type){
				const params = {
					bizParentType:52
				}
				orderNum(params).then(res=>{
					if(res.code == 0 ){
						// this.NoticeNum = res.data
						this.menuMessage.forEach(item=>{
							if(item.menuName === '订单信息')item.messageNumber = Number( res.data);
						})
					}
				})
			},
			//待办事项信息条树
			undoNum(){
				const params = {
					bizType: ['order', 'integral']
				};
				UndoWorkNum(params).then(res=>{

					if(res.code == 0 ){
						// this.NoticeNum = res.data
						this.menuMessage.forEach(item=>{
							if(item.menuName == '待办事项')item.messageNumber = Number( res.data);
						})
					}
				})
			},
			//系统消息 通知条数
			getMessageNotice(){
				getMessageNotice().then(res=>{
					if(res.code == 0 ){
						// this.NoticeNum = res.data
						this.menuMessage.forEach(item=>{
							if(item.menuName == '系统信息')item.messageNumber = Number( res.data);
						})
					}
				})
			},
			navigatTo(url){
				uni.navigateTo({
						url
				})
			},
			//系统消息、订单消息的完整已读
			isReadOrderOrSys(type){
				let params ={
					bizParentType:type
				}
				isReadOrderOrSys(params).then(res=>{
					if(res.code == 0 ){
						// this.NoticeNum = res.data
						console.log('res',res.data);
					}
				})
			},
			navTo(url,index) {
				if (!this.hasLogin) {
					uni.showModal({
						title: '提示',
						content: '您还未登录，不能进行此操作',
						confirmText: '去登录',
						cancelText: '取消',
						success: (suc) => {
							if (suc.confirm) {
								uni.navigateTo({
									url: '/pages/public/login'
								})
							}
						}
					})
				} else {
					console.log('index',index);
					if(index==0){
						this.isReadOrderOrSys(76)
						this.navigatTo(url)
					}else if(index == 1){
						this.isReadOrderOrSys(52)
						this.navigatTo(url)
					}else{
						this.navigatTo(url)
					}
					
				}
			},
		}
	}
</script>

<style lang='scss'>
	.content{
		border-top: 8rpx solid $my-bg-color-grey;
		border-bottom: 8rpx solid  $my-bg-color-grey;
		.menuContent{
			height: 150rpx;
			border-top: 8rpx solid $my-bg-color-grey;
			border-bottom: 8rpx solid  $my-bg-color-grey;
			
		}
	}
</style>
